#!/bin/bash

NUM_RUNS=20
MU_LIST="100 1000 10000 50000 100000 125000 150000 175000 200000 225000 235000 250000 300000 500000"

CARRIER_SLEEP_TIME=5
CREDITCO_SLEEP_TIME=5
MERCH_SLEEP_TIME=7
CUST_SLEEP_TIME=15

TRANS_PER_RUN=100

PROG=$1

if [ "$PROG" = "carrier" ]; then
   CMD="./carrier"
   SLEEP_TIME=$CARRIER_SLEEP_TIME
elif [ "$PROG" = "creditco" ]; then
   CMD="./creditco"
   SLEEP_TIME=$CREDITCO_SLEEP_TIME
elif [ "$1" = "customer" ]; then
   SLEEP_TIME=$CUST_SLEEP_TIME
   rm temp/*
elif [ "$1" = "merchant" ]; then
   SLEEP_TIME=$MERCH_SLEEP_TIME
   rm logs/*
else
   echo "Invalid program specified"
   exit 0;
fi

for mu in $MU_LIST;
do

  COUNTER=0

  if [ "$PROG" = "customer" ]; then
       CMD="./customer -m $mu -n $TRANS_PER_RUN"
  fi

 
  while [ $COUNTER -lt $NUM_RUNS ]; do
 
    if [ "$PROG" = "merchant" ]; then
       CMD="./merchant int_$mu" 
       CMD+="_#$COUNTER"
    fi

    echo $CMD for mu=$mu, run $COUNTER
    $CMD
    sleep $SLEEP_TIME
    killall $PROG
    let COUNTER=COUNTER+1

  done
done

